package com.yang.service.Impl;

import com.yang.mapper.AddressMapper;
import com.yang.entity.Address;
import com.yang.service.AddressService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    public List<Address> findAddressByUserId(Integer userId) {
        // 根据用户id查询地址信息
        return addressMapper.findAddressByUserId(userId);
    }

    @Override
    public void addAddress(Address address) {
        // 新增地址信息
        addressMapper.addAddress(address);
    }

    @Override
    public int userAddressCount(Integer userId) {
        // 查询用户地址数量
        List<Address> addressList = addressMapper.findAddressByUserId(userId);
        return addressList.size();
    }

    @Override
    public void deleteAddress(Integer userId, Integer addressId) {
        // 根据用户id和地址id删除地址信息
        addressMapper.deleteAddress(userId, addressId);
    }

    @Override
    public void updateAddress(Address address) {
        // 更新地址信息
        addressMapper.updateAddress(address);
    }
}
